﻿using System;
using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;

public class MyButton : MonoBehaviour
{
	public RectTransform panelTran;

	private bool isIn = false;
	private Tweener tweener = null;

	private void Start()
	{
		// Tweener对象保存这个动画的信息，每次调用do类型的方法都会创建一个tweener对象，这个对象是dotween来管理
		tweener = panelTran.DOLocalMove(new Vector3(0, 0, 0), 0.3f);
		tweener.SetAutoKill(false);//把autokill自动销毁设置为false
		tweener.Pause();
	}

	public void OnClick()
	{
		// panelTran.DOLocalMove(new Vector3(0, 0, 0), 0.3f);
		if (!isIn)
			panelTran.DOPlayForward();//前放
		else
			panelTran.DOPlayBackwards();//倒放，让panel离开屏幕
		
		isIn = !isIn;
	}

	private void Update()
	{
		if(Input.GetKey(KeyCode.A))
			Destroy(this.gameObject);
	}

	private void OnDestroy()
	{
		tweener.Kill();
	}
}
